package user_role_v1

import (
	"context"
	"gf-xb-api/internal/consts"
	"gf-xb-api/internal/dao"
	"gf-xb-api/internal/model/entity"
	"gf-xb-api/utility/xslice"
)

func (s *sUserRole) GetList(ctx context.Context, userId uint) (roleIds []uint, err error) {

	cols := dao.SysUserRole.Columns()
	var userRoles []*entity.SysUserRole
	err = dao.SysUserRole.Ctx(ctx).Where(cols.UserId, userId).Where(cols.Status, uint(consts.STATUS_ACTIVE)).Scan(&userRoles)
	if err != nil {
		return
	}

	roleIds = xslice.GetFieldSlice(userRoles, func(ur *entity.SysUserRole) uint { return ur.RoleId })

	return
}
